package top.kaoshanji.p1ch02a;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
import top.kaoshanji.p1ch02a.domain.User;
import top.kaoshanji.p1ch02a.service.UserService;

import java.util.Date;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/3 18:17
 */
@ContextConfiguration("classpath*:p1ch02a-context.xml")
public class UserServiceTest extends AbstractTransactionalTestNGSpringContextTests {

    @Autowired
    private UserService userService;

    @Test
    public void hasMatchUser() {
        boolean b1 = userService.hasMatchUser("admin", "123456");
        boolean b2 = userService.hasMatchUser("admin", "1111");

        Assert.assertTrue(b1);
        Assert.assertTrue(!b2);
    }

    @Test
    public void findUserByUserName() {
        User user = userService.findUserByUserName("admin");

        Assert.assertEquals(user.getUserName(), "admin");
    }


    @Test
    public void loginSuccess() {
        User user = userService.findUserByUserName("admin");

        /*user.setUserId(1);
        user.setUserName("admin");*/
        user.setLastIp("192.168.121.7");
        user.setLastVisit(new Date());

        userService.loginSuccess(user);
    }



}
